package com.spring.proxy.javassist.test;

import java.lang.reflect.Method;

import com.spring.proxy.javassist.JavassistClassLoader;
import com.spring.proxy.javassist.JavassistInvocationHandler;
import com.spring.proxy.javassist.JavassistProxy;

public class WokerProxy implements JavassistInvocationHandler {

	private Object target;
	
	public WokerProxy(Object target) {
		super();
		this.target = target;
	}
	public  Object getInstance() {
		return JavassistProxy.newProxyInstance(new JavassistClassLoader(), target.getClass().getInterfaces(), this);
	}
	@Override
	public Object invoke(Object arg0, Method arg1, Object[] arg2) throws Throwable {
		Object obj=null;
		before();
		obj = arg1.invoke(target, arg2);
		after();
		return obj;
	}
	private void after() {
		System.out.println("after");
	}
	private void before() {
		System.out.println("before");
	}

}
